package com.xiaocikuai.smallchunks.mapper.Card;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xiaocikuai.smallchunks.entity.Card.CardChunks;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public interface CardChunksMapper extends BaseMapper<CardChunks> {
    @Insert("INSERT INTO card_chunks (cid, word_id, front, back, back_hl, front_hl, product_id, create_time, update_time, sort) " +
            "VALUES (#{cid}, #{wordId}, #{front}, #{back}, #{backHl}, #{frontHl}, #{productId}, #{createTime}, #{updateTime}, #{sort})")
    boolean insertCardChunk(CardChunks cardChunk);

    @Insert("INSERT INTO collection (cid, uid, time) " +
            "VALUES (#{cid}, #{uid}, #{time})")
    boolean collectionAdd(int cid, long uid, LocalDateTime time);

    @Delete("DELETE FROM collection WHERE cid = #{cid} AND uid = #{uid}")
    boolean collectionDel(int cid, long uid);

    @Select("SELECT COUNT(*) FROM collection WHERE cid = #{cid} AND uid = #{uid}")
    int isCollect(int cid, long uid);

//    @Select("SELECT * FROM card_chunks WHERE cid = #{cid}")
//    CardChunks getCardById(int cid);

    @Select("SELECT * FROM card_chunks WHERE cid = #{cid} ")
    CardChunks getCardById(int cid);


//    @Select({
//            "SELECT * FROM card_chunks WHERE id IN (" +
//                    String.join(",", Stream.generate(() -> "?").limit(recodeList.size()).toArray(String[]::new)) +
//                    ")"
//    })
//    List<CardChunks> getCardsByIds(@Param("recodeList") List<Integer> recodeList);



//    @Select({"SELECT * FROM card_chunks WHERE id IN (" +
//            "<foreach item='id' index='index' collection='recodeList' open='(' separator=',' close=')'>" +
//            "#{recodeList}" +
//            "</foreach>)"})
//    List<CardChunks> getCardsByIds(@Param("recodeList") List<Integer> recodeList);

}
